﻿using System;
using PB.Interfaces;
using PB.Helpers.CustomCollections;
using PB.Helpers;
using System.IO;
using System.Collections.Generic;
using PB.Base;

namespace PB.LOG
{
    public sealed class Logger : ILogger
    {
        private string _fileName = String.Empty;
        private bool _userOwnerLogs = false;
        private string _appName = String.Empty;      
        
        private string DefaultPath()
        {
            return AppDomain.CurrentDomain.FriendlyName + ".xml";
        }                

        public Logger()
        {
            this._fileName = this.DefaultPath();

            XmlHelper.SetPath(this._fileName);
        }

        public Logger(string filename)
        {
            string checkedPath = Utilities.CheckedPathXml(filename);

            this._fileName = checkedPath;

            XmlHelper.SetPath(checkedPath);
        }

        public Logger(bool userOwnerLogs)
        {
            this._fileName = this.DefaultPath();

            XmlHelper.SetPath(this._fileName);

            this._userOwnerLogs = userOwnerLogs;  
        }

        public Logger(string filename, bool userOwnerLogs)
        {
            string checkedPath = Utilities.CheckedPathXml(filename);

            this._fileName = checkedPath;

            XmlHelper.SetPath(checkedPath);
            
            this._userOwnerLogs = userOwnerLogs;
        }

        public string FileName
        {
            get { return this._fileName; }
            set { this._fileName = value; }
        }

        public string ApplicationName
        {
            get { return this._appName; }
            set { this._appName = value; }
        }

        public bool UserOwnerLogs
        {
            get { return this._userOwnerLogs; }
            set { this._userOwnerLogs = value; }
        }

        public UsersCollection Users
        {
            get
            {
                UsersCollection coll = new UsersCollection(this._userOwnerLogs);
                coll.users = XmlHelper.Users.GetUsers();

                return coll;
            }
        }

        public LogsCollection Logs
        {
            get
            {
                LogsCollection coll = new LogsCollection();
                coll.logs = XmlHelper.Logs.GetLogs();

                return coll;
            }
        }

        public void Delete()
        {
            XmlHelper.Delete();
        }
    }
}
